package server

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"server-asset/internal/model/entity"
)

type cServer struct{}

func NewServer() *cServer {
	return &cServer{}
}

// 获取服务器列表
func (c *cServer) List(r *ghttp.Request) {
	var servers []entity.Server
	err := g.Model("server").Ctx(r.Context()).OrderDesc("id").Scan(&servers)
	if err != nil {
		r.Response.WriteJsonExit(g.Map{"code": 500, "msg": err.Error()})
		return
	}
	r.Response.WriteJson(g.Map{"code": 0, "data": servers})
}
